package com.example.service;

import com.example.entity.User;
import com.example.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    public User login(String username, String password) {
        return userRepository.findByUsernameAndPassword(username, password);
    }

    public boolean register(String username, String password, String userType) {
        if (userRepository.findByUsername(username) != null) {
            return false; // 用户名已存在
        }
        User user = new User(username, password, userType);
//        user.setUsername(username);
//        user.setPassword(password);
//        user.setUserType(userType);
        userRepository.save(user);
        return true;
    }
}